#ifndef _Philosophers_Philosophers_h
#define _Philosophers_Philosophers_h

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

#define LAYOUTFILE <Philosophers/Philosophers.lay>
#include <CtrlCore/lay.h>

#define TOPICFILE <Philosophers/app.tpp/all.i>
#include <Core/topic_group.h>

#include "Person.h"
#include "NewGame.h"
#include "About.h"

// Game and main window class
class Philosophers : public WithPhilosophersLayout<TopWindow> {
	typedef Philosophers CLASSNAME; // class name macro
	MenuBar menu; // mane menu
	StatusBar status; // status bar
	NewGameDlg ng; // new game dialog
	HelpWindow help; // help dialog
	AboutDlg about; // about dialog
	int speed; // game speed
	int maxHunger; // starvation threshold
	int regHunger; // max. registered hunger
	bool stopDead; // stop on starvation threshold or deadlock
	bool running; // whether the modeling is running
	String logFile; // log output file
	FileOut log; // log file stream
	
	Array<Person> phils; // philosophers vector (each is a container)
	Vector<Time> waiting; // current waiting for each person
	
	void MainMenu(Bar &); // makes main menu
	void GameMenu(Bar &); // makes "Modeling" menu
	void NewGame(); // new game
	void Start(); // starts modeling
	void Stop(); // stops modeling
	void Exit(); // quits the application
	void HelpMenu(Bar &); // makes "Help" menu
	void Help(); // displays help
	void About(); // displays about
public:
	Philosophers(); // constructor
	void Log(String); // logging
	void CheckHunger(int, int); // hunger level registration
	void CheckPlot(int); // detects "neighbor plot"
	void CheckDeadlock(); // detects "starvation"
	void Update(int, PersonInfo); // updates records in list
	void UpdateFork(int, int); // updates fork info
	
	int GetSpeed() const; // returns game speed
};

#endif
